

def str_iter(str1):
    list1 = []
    for index, item in enumerate(str1):
        index_str = ""
        for item2 in str1[index:]:
            index_str = index_str + item2
            list1.append(index_str)
    return list1


def str_find(list_str1, list_str2):
    list1 = []
    for str1 in list_str1:
        for str2 in list_str2:
            if str1 == str2:
                list1.append(str1)
    return list1


def find_common_characters(str1, str2):
    common_substrings = set()

    # 获取两个字符串的长度
    len1, len2 = len(str1), len(str2)

    # 遍历第一个字符串的所有子字符串
    for i in range(len1):
        for j in range(i + 1, len1 + 1):
            substring = str1[i:j]
            # 检查该子字符串是否在第二个字符串中
            if substring in str2:
                common_substrings.add(substring)

    return common_substrings


def find_overlapping_strings(s1, s2):
    overlaps = []
    len_s1 = len(s1)
    len_s2 = len(s2)
    for start1 in range(len_s1):
        for end1 in range(start1 + 1, len_s1 + 1):
            sub_s1 = s1[start1:end1]
            for start2 in range(len_s2):
                for end2 in range(start2 + 1, len_s2 + 1):
                    sub_s2 = s2[start2:end2]
                    if sub_s1 == sub_s2:
                        overlaps.append(sub_s1)
    return list(set(overlaps))


if __name__ == '__main__':
    demo1 = "abcd"
    demo2 = "bcd"
    # list1 = str_find(str_iter(demo1), str_iter(demo2))
    # print(list1)

    print(find_common_characters(demo1, demo2))

    print(find_overlapping_strings(demo1, demo2))
